﻿using System;
using Nofs.Net.nofs.metadata.interfaces;
using Nofs.Net.Annotations;
using biz.ritter.javapi.lang.reflect;

namespace Nofs.Net.AnnotationDriver
{

    public class MethodFilter : IMethodFilter
    {
        private AttributeCache _hasContainerAttribute;
        private AttributeCache _hasContainerManagerAttribute;
        private AttributeCache _hasFolderObjectAttribute;
        private AttributeCache _hasExecutableAttribute;
        private AttributeCache _hasDomainObjectAttribute;
        private AttributeCache _hasProvidesNameAttribute;

        public MethodFilter()
        {
            _hasContainerAttribute = new AttributeCache(typeof(INeedsContainer).getClass());
            _hasContainerManagerAttribute = new AttributeCache(typeof(INeedsContainerManager).getClass());
            _hasFolderObjectAttribute = new AttributeCache(typeof(IFolderObject).getClass());
            _hasExecutableAttribute = new AttributeCache(typeof(IExecutable).getClass());
            _hasDomainObjectAttribute = new AttributeCache(typeof(IDomainObject).getClass());
            _hasProvidesNameAttribute = new AttributeCache(typeof(IProvidesName).getClass());
        }

        public bool UseMethod(Object parent, Method method) //throws Exception 
        {
            return !(
                _hasContainerAttribute.hasAnnotation(method) ||
                _hasContainerManagerAttribute.hasAnnotation(method) ||
                _hasFolderObjectAttribute.hasAnnotation(method) ||
                _hasExecutableAttribute.hasAnnotation(method) ||
                _hasDomainObjectAttribute.hasAnnotation(method) ||
                _hasProvidesNameAttribute.hasAnnotation(method)
            );
        }
    }

}
